<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .register {
      width: 600px;
      margin: 100px auto;
    }

    .message {
      display: inline-block;
      color: #333;
      font-size: 12px;
      background: url(img/mess.png) no-repeat;
      padding-left: 20px;
    }

    .wrong {
      color: red;
      background: url(img/wrong.png) no-repeat;
    }

    .right {
      color: green;
      background: url(img/right.png) no-repeat;
    }
  </style>
</head>

<body>
  <div class="register">
    <input type="password" class="ipt">
    <p class="message"> 请输入6-16位密码</p>
  </div>
  <script>
    var ipt = document.querySelector('.ipt');
    var message = document.querySelector('.message');
    ipt.onblur = function () {
      if (this.value.length < 6 || this.value.length > 16) {
        message.className = 'message wrong';
        message.innerHTML = '您输入的位数不对，请输入6-16位的密码'
      } else {
        message.className = 'message right';
        message.innerHTML = '您输入的对了'
      }
    }
  </script>
</body>

</html>